package com.dearbinge.data.service.impl.commodity;

import com.baomidou.mybatisplus.plugins.Page;
import com.dearbinge.data.api.commodity.CommodityCommissionService;
import com.dearbinge.data.api.commodity.CommodityMessageService;
import com.dearbinge.data.api.moments.BusinessCircleCommentService;
import com.dearbinge.data.dao.*;
import com.dearbinge.data.dao.collect.CommodityCollectMapper;
import com.dearbinge.data.dao.commodity.CommodityBrandInfoMapper;
import com.dearbinge.data.dao.commodity.CommodityCommissionMapper;
import com.dearbinge.data.dao.commodityspec.CommoditySpecMapper;
import com.dearbinge.data.dao.moments.BusinessCircleClickMapper;
import com.dearbinge.data.dao.moments.BusinessCircleMapper;
import com.dearbinge.data.dao.shopgenre.ShopGenreMapper;
import com.dearbinge.data.dto.commodity.CommodityMessageDto;
import com.dearbinge.data.pojo.collect.Collect;
import com.dearbinge.data.pojo.commodity.CommodityBrandInfoDO;
import com.dearbinge.data.pojo.commodity.CommodityCommissionDO;
import com.dearbinge.data.pojo.commodity.CommodityMessage;
import com.dearbinge.data.pojo.commodity.ShopGenre;
import com.dearbinge.data.pojo.commodity.dto.CommodityCommissionResultDTO;
import com.dearbinge.data.pojo.commodity.dto.CommodityDTO;
import com.dearbinge.data.pojo.commodity.vo.*;
import com.dearbinge.data.pojo.commodityBeShop.CommodityBeShop;
import com.dearbinge.data.pojo.commodityspec.CommoditySpec;
import com.dearbinge.data.pojo.commodityspec.vo.CommoditySpecRequestVO;
import com.dearbinge.data.pojo.commodityspec.vo.CommoditySpecResponseVO;
import com.dearbinge.data.pojo.moments.BusinessCircleClickDO;
import com.dearbinge.data.pojo.orderTable.dto.OrderTotalPriceDTO;
import com.dearbinge.data.pojo.shopManage.ShopManage;
import com.dearbinge.utils.*;
import com.dearbinge.utils.date.DateUtils;
import com.dearbinge.utils.enums.ResultStatusCodeEnum;
import com.dearbinge.utils.enums.TypeCodeEnum;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * 商品信息 业务层
 *
 * @author wes
 * @date 2019/1/12
 */
@Service(value = "commodityMessageService")
public class CommodityMessageServiceImpl implements CommodityMessageService {

    @Autowired
    private CommodityMessageMapper commodityMessageMapper;
    @Autowired
    private BusinessCircleMapper businessCircleMapper;
    @Autowired
    private CommodityBeShopMapper commodityBeShopMapper;
    @Autowired
    private ShopManageMapper shopManageMapper;
    @Autowired
    private CommodityCollectMapper commodityCollectMapper;
    @Autowired
    private ThumbsMapper thumbsMapper;
    @Autowired
    private BusinessCircleCommentService businessCircleCommentService;
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private CommodityBrandInfoMapper commodityBrandInfoMapper;
    @Autowired
    private CommoditySpecMapper commoditySpecMapper;
    @Autowired
    private CommodityCommissionMapper commodityCommissionMapper;
    @Autowired
    private ShopGenreMapper shopGenreMapper;
    @Autowired
    private CommodityCommissionService commodityCommissionService;
    @Autowired
    private OrderDetailTableMapper orderDetailTableMapper;
    @Autowired
    private BusinessCircleClickMapper businessCircleClickMapper;
    /**
     * 商品信息 增加
     * @param commodityMessageVO 商品接受
     * @return 结果提示
     */
    @Override
    public Integer insert(CommodityMessageRequestVO commodityMessageVO) {
        String userId = commodityMessageVO.getUserId();
        //计算总库存
        List<CommoditySpecRequestVO> listSpec = commodityMessageVO.getListSpec();
        int stock=0;
        for (CommoditySpecRequestVO commoditySpecRequestVO : listSpec) {
            Integer stockCount = commoditySpecRequestVO.getStockCount();
            stock +=stockCount;
        }
        CommodityMessage commodityMessage = new CommodityMessage();
        commodityMessage.setCommodityStock(stock);
        BeanUtils.copyProperties(commodityMessageVO,commodityMessage);
        //增加品牌表
        Integer brandId = insertBrandInfo(commodityMessageVO, commodityMessage);
        if (brandId !=null) {
            commodityMessage.setBrand(brandId.toString());
        }
        //封装店铺id 编码 库存
        ShopManage shopManage = shopManageMapper.getByUserId(userId);
        commodityMessage.setCommodityShopId(shopManage.getId().toString());
        commodityMessage.setCommodityCode(CodeUtil.getCommodityCode());
        //增加商品信息
        Integer commodity = commodityMessageMapper.insert(commodityMessage);
        commodityMessageVO.setId(commodityMessage.getId());
        //插入规格表
        insertSpec(commodityMessageVO);
        //插入佣金
        CommodityCommissionRequestVO commodityCommissionRequestVO = commodityMessageVO.getCommodityCommissionRequestVO();
        CommodityCommissionDO commodityCommissionDO = new CommodityCommissionDO();
        commodityCommissionDO.setCommodityId(commodityMessage.getId());
        BeanUtils.copyProperties(commodityCommissionRequestVO,commodityCommissionDO);
         commodityCommissionMapper.insert(commodityCommissionDO);
        //增加社交圈信息
        Integer circle = businessCircleMapper.insertCommodityMessage(commodityMessage);
        insertClick(commodityMessage);
        //增加商品关系表
        Integer shop = insertCommodityBeShop(commodityMessage);
        return commodity + circle + shop;
    }

    private void insertClick(CommodityMessage commodityMessage) {
        BusinessCircleClickDO businessCircleClickDO = new BusinessCircleClickDO();
        String userId = commodityMessage.getUserId();
        businessCircleClickDO.setCommodityId(commodityMessage.getId());
        businessCircleClickDO.setUserId(Integer.valueOf(userId));
        businessCircleClickDO.setCreateBy(userId);
        businessCircleClickDO.setModifyBy(userId);
        businessCircleClickMapper.insert(businessCircleClickDO);
    }


    /**
     * 商品信息 修改
     * @param commodityMessageRequestVO 商品信息
     * @return 结果提示
     */
    @Override
    public Integer update(CommodityMessageRequestVO commodityMessageRequestVO) {
        CommodityMessage commodityMessage = new CommodityMessage();
        //如果有修改品牌
        CommodityBrandInfoRequestVO commodityBrandInfoRequestVO = commodityMessageRequestVO.getCommodityBrandInfoRequestVO();
        //品牌id
        String brand = null;
        if ( commodityBrandInfoRequestVO!=null) {
            //如果有id 修改 没有id 新增
            Integer brandId = commodityBrandInfoRequestVO.getBrandId();
            CommodityBrandInfoDO commodityBrandInfoDO = new CommodityBrandInfoDO();
            BeanUtils.copyProperties(commodityBrandInfoRequestVO,commodityBrandInfoDO);
            if (brandId != null) {
                commodityBrandInfoMapper.update(commodityBrandInfoDO);
            } else {
                //新增品牌 将新增的品牌id返回到商品对象去更新
                commodityBrandInfoMapper.insert(commodityBrandInfoDO);
                brand = commodityBrandInfoDO.getBrandId().toString();
            }
        }
        //如果有修改佣金
        CommodityCommissionRequestVO commodityCommissionRequestVO = commodityMessageRequestVO.getCommodityCommissionRequestVO();
        if ( commodityCommissionRequestVO !=null) {
            CommodityCommissionDO commodityCommissionDO = new CommodityCommissionDO();
            BeanUtils.copyProperties(commodityCommissionRequestVO,commodityCommissionDO);
            commodityCommissionMapper.updateById(commodityCommissionDO);
        }
        //如果有修改规格
        List<CommoditySpecRequestVO> listSpec = commodityMessageRequestVO.getListSpec();
        Integer total = 0;
        if ( listSpec!=null) {
            for (CommoditySpecRequestVO commoditySpecRequestVO : listSpec) {
                CommoditySpec commoditySpec = new CommoditySpec();
                BeanUtils.copyProperties(commoditySpecRequestVO,commoditySpec);
                commoditySpec.setCommodityId(commodityMessageRequestVO.getId());
                Integer id = commoditySpecRequestVO.getId();
                //如果规格有id 修改 没有就新增
                if (id !=null) {
                    if (commoditySpecRequestVO.getDeleted()) {
                        commoditySpecMapper.delete(commoditySpecRequestVO.getId());

                    } else {
                        //如果delete是1 走删除 否则走修改
                        commoditySpecMapper.update(commoditySpec);
                        Integer count = commoditySpecRequestVO.getStockCount();
                        total +=count;
                    }
                } else {
                    commoditySpecMapper.insert(commoditySpec);
                    Integer count = commoditySpecRequestVO.getStockCount();
                    total +=count;
                }
            }
            commodityMessage.setCommodityStock(total);
        }
        //修改商品信息
        BeanUtils.copyProperties(commodityMessageRequestVO,commodityMessage);
        if (brand != null) {
            commodityMessage.setBrand(brand);
        }
        Integer commodity = commodityMessageMapper.update(commodityMessage);
        //修改社交圈信息
        Integer circle = businessCircleMapper.updateCommodityMessage(commodityMessage);
        return commodity+circle;
    }

    /**
     * 商品信息 删除
     * @param id 主键id
     * @return 结果
     */
    @Override
    public Integer deleteCommodityMessage(Integer id) {
        return commodityMessageMapper.deleteCommodityMessage(id);
    }


    /**
     * 根据id查询商品信息
     * @param id id
     * @return 商品信息
     */
    @Override
    public CommodityMessageDto getById(Integer id) {
       CommodityMessage commodityMessage =  commodityMessageMapper.getById(id);
        List<CommodityMessage> list = new ArrayList<CommodityMessage>();
        List<CommodityMessageDto> dtoList = new ArrayList<CommodityMessageDto>();
        if (commodityMessage != null) {
           list.add(commodityMessage);
           dtoList = resultMsg(list);
       }
        return dtoList.get(0);
    }

    /**
     * 分页根据商品类目查询商品集
     *
     * @param categoryId 商品id
     * @return 商品集
     */
    @Override
    public Page listCommodityByCategory(String categoryId, Integer lastId,Integer current, Integer size) {
        current = PageUtils.getDefaultValues(current, 1);
        size = PageUtils.getDefaultValues(size, 10);
        Page page = new Page(current, size);
        List<CommodityMessage> list = commodityMessageMapper.listCommodityByCategory(categoryId, lastId,page);
        List<CommodityMessageResponseVO> result = BeanMapperUtil.map(list, CommodityMessageResponseVO.class);
        for (CommodityMessageResponseVO commodityMessageResponseVO : result) {
            //商品月销量
            Integer total = orderDetailTableMapper.countByCommodityId(commodityMessageResponseVO.getId().toString());
            commodityMessageResponseVO.setMonthlySales(total);
        }
        //查出总条数
        Integer count = commodityMessageMapper.countCommodityByCategory(categoryId);
        //最大数
        page.setTotal(count);
        page.setRecords(result);
        return page;
    }


    /**
     * 根据商品id查询商品详情
     * @param userId 当前登录的用户id
     * @param otherId 转发商品的用户id（下家）
     * @param commodityId 商品id
     * @return 提示信息
     */
    @Override
    public  ResultMsg<CommodityDetailsVO> getCommodityMessageById(String userId,String otherId, Integer commodityId) {
        CommodityMessage commodityMessage = commodityMessageMapper.getCommodityById(commodityId);
        if (commodityMessage == null ) {
            return  ResultMsg.error(ResultStatusCodeEnum.CODE5002.getCode(),"商品id不存在");
        }
        if (commodityMessage.getDeleted()) {
            return  ResultMsg.error(ResultStatusCodeEnum.CODE5002.getCode(),"商品已删除");
        }
        if (!commodityMessage.getCommodityStatus()) {
            return  ResultMsg.error(ResultStatusCodeEnum.CODE5002.getCode(),"商品已下架");
        }
        /*返回商品信息 规格信息 店铺名字 上架数量 优惠券折扣*/
        String nullString = "null";
        //是否有优惠效果
        boolean  couponStatus =true ;
        if (nullString.equals(otherId) || StringUtils.isEmpty(otherId)||commodityMessage.getUserId().equals(otherId)) {
            couponStatus =false;
        }
        CommodityDetailsVO commodityDetailsVO = new CommodityDetailsVO();
        commodityDetailsVO.setCouponStatus(couponStatus);
        //返回商品信息
        CommodityMessageResponseVO commodityMessageResponseVO = new CommodityMessageResponseVO();
        BeanUtils.copyProperties(commodityMessage,commodityMessageResponseVO);
        //商品月销量
        Integer total = orderDetailTableMapper.countByCommodityId(commodityId.toString());
        commodityMessageResponseVO.setMonthlySales(total);
        commodityDetailsVO.setCommodityMessageResponseVO(commodityMessageResponseVO);
        //店铺名字
        ShopManage shopManage = shopManageMapper.getByUserId(commodityMessage.getUserId());
        commodityDetailsVO.setShopName(shopManage.getShopName());
        //店铺上架商品数量
        int num = commodityMessageMapper.countByShopIdAndStatus(commodityMessage.getCommodityShopId(), true);
        commodityDetailsVO.setCommodityNum(num);
        //封装展示价优惠金额
        BigDecimal discountPct = null;
        if (couponStatus) {
            CommodityCommissionResultDTO discount = commodityCommissionService.getDiscount(commodityId);
            commodityDetailsVO.setCouponDiscountPrice( discount.getDiscountPrice());
            BigDecimal one = new BigDecimal(1);
            BigDecimal ten = new BigDecimal(10);
             discountPct = one.subtract(discount.getDiscountPct());
            double result= discountPct.multiply(ten).doubleValue();
            commodityDetailsVO.setCouponDiscount(result);
        }
        //封装规格
        List<CommoditySpecResponseVO> specVOList = new ArrayList<CommoditySpecResponseVO>();
        List<CommoditySpec> specDOList = commoditySpecMapper.listByCommodityId(commodityId);
        for (CommoditySpec commoditySpec : specDOList) {
            CommoditySpecResponseVO commoditySpecResponseVO = new CommoditySpecResponseVO();
            BeanUtils.copyProperties(commoditySpec,commoditySpecResponseVO);
            //增加券后价
            if (couponStatus) {
                BigDecimal retailPrice = commoditySpecResponseVO.getRetailPrice();
                BigDecimal discountPrice = retailPrice.multiply(discountPct);
                commoditySpecResponseVO.setDiscountPrice(discountPrice);
            }
            specVOList.add(commoditySpecResponseVO);
        }
        commodityDetailsVO.setListSpec(specVOList);
        //商品是否收藏
        Collect collect = commodityCollectMapper.getCollect(userId, commodityId.toString());
        if (collect != null) {
            commodityDetailsVO.setCollectStatus(true);
            commodityDetailsVO.setCollectId(collect.getId());
        } else {
            commodityDetailsVO.setCollectStatus(false);
        }
        return ResultMsg.ok(commodityDetailsVO);
    }



    /**
     * 公共日期转换方法
     * @param list 商品信息
     * @return 转化结果
     */
    private List<CommodityMessageDto> resultMsg(List<CommodityMessage> list){
        CommodityMessage commodityMessage ;
        List<CommodityMessageDto> dtoList = new ArrayList<CommodityMessageDto>();
        for (int index = 0;index < list.size();index++){
            CommodityMessageDto dto = new CommodityMessageDto();
            commodityMessage = list.get(index);
            dto.setCommodityId(commodityMessage.getId());
            dto.setContent(commodityMessage.getContent());
            dto.setCreateTime(DateUtils.date2String(commodityMessage.getCreateTime()));
            dto.setUserId(commodityMessage.getUserId());
            dtoList.add(dto);
        }
        return dtoList;
    }


    /**
     * 查询上下架的商品
     *
     * @param userId          用户id
     * @param commodityStatus 上下架状态
     * @param current         当前页
     * @param size            每页展示条数
     * @return 商品集合
     */
    @Override
    public Page listByCommodityStatus(String userId, Boolean commodityStatus, Integer current, Integer size) {
        current = PageUtils.getDefaultValues(current, 1);
        size = PageUtils.getDefaultValues(size, 10);
        //分页
        Page page = new Page(current, size);
        List<CommodityMessage> list = commodityMessageMapper.listByCommodityStatus(userId,commodityStatus, page);
        //简化数据
        List<CommodityMessageResponseVO> result = BeanMapperUtil.map(list, CommodityMessageResponseVO.class);
        //查出总条数
        Integer count = commodityMessageMapper.countByCommodityStatus(userId,commodityStatus);
        //最大数
        page.setTotal(count);
        page.setRecords(result);
        return page;
    }

    /**
     * 校验订单金额
     *
     * @param orderTotalPriceDTO 订单价格dto
     * @return 校验结果
     */
    @Override
    public Boolean getCommodityTotal(OrderTotalPriceDTO orderTotalPriceDTO) {
        //传进来的总价
        BigDecimal intPrice = orderTotalPriceDTO.getTotalPrice();
        BigDecimal totalPrice = new BigDecimal("0");
        List<CommodityDTO> goodsList = orderTotalPriceDTO.getGoodsList();
        for (CommodityDTO commodityDTO : goodsList) {
            //根据商品id查单价
            CommodityMessage commodity = commodityMessageMapper.getById(commodityDTO.getCommodityId());
            BigDecimal retailPrice = commodity.getRetailPrice();
            BigDecimal buyNum = new BigDecimal(commodityDTO.getBuyNum().toString());
            BigDecimal price = retailPrice.multiply(buyNum);
            totalPrice =  totalPrice.add(price);
        }
        //判断结果是否相等
        return PriceUtils.checkEqualPrice(intPrice, totalPrice);
    }

    /**
     * 用户能否发商品
     * 店铺类型为个人 只能发十条商品 认证状态 店铺状态必须有效
     * @param userId 用户id
     * @return 能否
     */
    @Override
    public ResultMsg<Boolean> checkAddCommodityStatus(String userId) {
        ShopManage shopManage = shopManageMapper.getByUserId(userId);
        if (shopManage != null) {
            Integer attestationStatus = shopManage.getAttestationStatus();
            Integer shopStatus = shopManage.getShopStatus();
            Integer shopStyle = shopManage.getShopStyle();
            if (attestationStatus == 1 && shopStatus == 1) {
                if ( shopStyle == 0 ) {
                    Integer total = commodityMessageMapper.countByCommodityStatus(userId,true);
                    if (total < 10) {
                        return  ResultMsg.okData(true,"允许发布商品");
                    }else {
                        return  ResultMsg.errorData(501,false,"个人最发10条商品");
                    }
                }
                return  ResultMsg.okData(true,"允许发布商品");
            }
        }
        return  ResultMsg.errorData(501,false,"店铺未通过审核");
    }



    /**
     * 修改商品上下架
     * @param commodityId 商品id
     * @param commodityStatus 商品状态 （0下架 1上架）
     * @return 影响行数
     */
    @Override
    public Integer updateCommodityStatus(Integer commodityId,Boolean commodityStatus) {
        return   commodityMessageMapper.updateCommodityStatus(commodityId,commodityStatus);
    }

    /**
     * 分页查分销商品
     *
     * @param shopId  店铺id
     * @param current 当前页
     * @param size    每页条数
     * @return 商品列表
     */
    @Override
    public Page listForwardCommodity(Integer shopId, Integer current, Integer size) {
        current = PageUtils.getDefaultValues(current, 1);
        size = PageUtils.getDefaultValues(size, 10);
        Page page = new Page(current, size);
        //分销类型为1
        int type = 1;
        List<CommodityBeShop> list = commodityBeShopMapper.listByType(shopId.toString(),type, page);
        List<CommodityForwardVO> arrayList = new ArrayList<>();
        for (CommodityBeShop commodityBeShop : list) {
            Integer commodityId = Integer.valueOf(commodityBeShop.getCommodityId());
            CommodityMessage commodityMessage = commodityMessageMapper.getCommodityById(commodityId);
            CommodityForwardVO commodityForwardVO = new CommodityForwardVO();
            if (commodityMessage != null) {
                BeanUtils.copyProperties(commodityMessage,commodityForwardVO );
                commodityForwardVO.setCommodityId(commodityId);
                //商品是否失效 （下架、删除）
                if (commodityMessage.getDeleted()|| !commodityMessage.getCommodityStatus() ) {
                    commodityForwardVO.setForwardStatus(false);
                } else {
                    commodityForwardVO.setForwardStatus(true);
                }
                //封装店铺名字
                ShopManage shopManage = shopManageMapper.getById(shopId);
                commodityForwardVO.setShopId(shopId);
                if (shopManage != null) {
                    commodityForwardVO.setShopName(shopManage.getShopName());
                }
                //封装展示价佣金
                CommodityCommissionResultDTO discount = commodityCommissionService.getDiscount(commodityId);
                BigDecimal commissionPrice = discount.getCommissionPrice();
                commodityForwardVO.setCommissionPrice(commissionPrice);
                arrayList.add(commodityForwardVO);
            }
        }
        //查出总条数
        Integer count = commodityBeShopMapper.countByType(shopId.toString(),type);
        //最大数
        page.setTotal(count);
        page.setRecords(arrayList);
        return page;
    }

    /**
     * 数据回响 修改商品
     *
     * @param commodityId 商品id
     * @return 商品对象
     */
    @Override
    public CommodityMessageRequestVO getCommodityResponse(Integer commodityId) {
        CommodityMessage commodityMessage = commodityMessageMapper.getById(commodityId);
        CommodityMessageRequestVO commodityMessageRequestVO = new CommodityMessageRequestVO();
        if (commodityMessage != null) {
            BeanUtils.copyProperties(commodityMessage,commodityMessageRequestVO);
            //封装品牌
            String brand = commodityMessage.getBrand();
            if (!StringUtils.isEmpty(brand)) {
                CommodityBrandInfoDO brandInfo = commodityBrandInfoMapper.getById(Integer.valueOf(brand));
                CommodityBrandInfoRequestVO commodityBrandInfoRequestVO = new CommodityBrandInfoRequestVO();
                BeanUtils.copyProperties(brandInfo ,commodityBrandInfoRequestVO);
                commodityMessageRequestVO.setCommodityBrandInfoRequestVO(commodityBrandInfoRequestVO);
            }
            //规格
            List<CommoditySpec> list = commoditySpecMapper.listByCommodityId(commodityId);
            List<CommoditySpecRequestVO> map = BeanMapperUtil.map(list, CommoditySpecRequestVO.class);
            commodityMessageRequestVO.setListSpec(map);
            //佣金
            CommodityCommissionDO commodityCommissionDO = commodityCommissionMapper.getByCommodityId(commodityId);
            CommodityCommissionRequestVO commodityCommissionRequestVO = new CommodityCommissionRequestVO();
            BeanUtils.copyProperties(commodityCommissionDO,commodityCommissionRequestVO);
            commodityMessageRequestVO.setCommodityCommissionRequestVO(commodityCommissionRequestVO);
            //分类名字
            String commodityType = commodityMessage.getCommodityType();
            if (commodityType !=null) {
                ShopGenre shopGenre = shopGenreMapper.getByCategoryCode(commodityType);
                if (shopGenre !=null && shopGenre.getName() != null) {
                    commodityMessageRequestVO.setCategoryName(shopGenre.getName());
                }
            }
        }
        return commodityMessageRequestVO;
    }


    private void insertSpec(CommodityMessageRequestVO commodityMessageVO) {
        List<CommoditySpecRequestVO> listSpec = commodityMessageVO.getListSpec();
        for (CommoditySpecRequestVO commoditySpecRequestVO : listSpec) {
            CommoditySpec commoditySpec = new CommoditySpec();
            BeanUtils.copyProperties(commoditySpecRequestVO,commoditySpec);
            commoditySpec.setCommodityId(commodityMessageVO.getId());
            commoditySpecMapper.insert(commoditySpec);
        }
    }

    private Integer insertBrandInfo(CommodityMessageRequestVO commodityMessageVO, CommodityMessage commodityMessage) {
        CommodityBrandInfoRequestVO commodityBrandInfoRequestVO = commodityMessageVO.getCommodityBrandInfoRequestVO();
        CommodityBrandInfoDO commodityBrandInfoDO = new CommodityBrandInfoDO();
        if (!StringUtils.isEmpty(commodityBrandInfoRequestVO)) {
            BeanUtils.copyProperties(commodityBrandInfoRequestVO,commodityBrandInfoDO);
            if (!StringUtils.isEmpty(commodityBrandInfoDO) && commodityBrandInfoDO.getBrandName() != null) {
                 commodityBrandInfoMapper.insert(commodityBrandInfoDO);
                commodityMessage.setBrand( commodityBrandInfoDO.getBrandId().toString());
            }
        }
        return commodityBrandInfoDO.getBrandId();
    }

    private Integer insertCommodityBeShop(CommodityMessage commodityMessage) {
        String userId = commodityMessage.getUserId();
        CommodityBeShop commodityBeShop = new CommodityBeShop();
        commodityBeShop.setCommodityId(commodityMessage.getId().toString());
        commodityBeShop.setShopId(commodityMessage.getCommodityShopId());
        commodityBeShop.setCreateBy(userId);
        commodityBeShop.setModifyBy(userId);
        commodityBeShop.setCommodityType(TypeCodeEnum.COMMODITY_DIRECT.getCode());
        return commodityBeShopMapper.insert(commodityBeShop);
    }




}
